<style scoped>
    .plan-summary-page{}
    .plan-summary-page .el-dialog__body#noValidQuotation{padding:10px 20px!important;}

</style>
<template>
    <div class="plan-summary-page">
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
            <el-tab-pane label="按计划汇总" name="1">
                <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
                    <el-form-item label="法人名称" class="selectMB10">
                        <el-select size="mini" v-if="legalPersonDropDown.length>1" clearable v-model="formInline.legalPersonName"  @change="selectLegalPersonName" placeholder="请选择">
                            <el-option v-for="(legalPerson,index) in legalPersonDropDown" :key="index" :label="legalPerson.legalPersonName":value="legalPerson.legalPersonName">
                                <span>{{ legalPerson.legalPersonName }}</span>
                            </el-option>
                        </el-select>
                        <el-input size="mini" v-else disabled v-model="formInline.legalPersonName" placeholder=""></el-input>
                    </el-form-item>
                    <el-form-item label="计划编号" class="selectMB10">
                        <el-input size="mini" v-model="formInline.planCode" placeholder="请输入计划编号"></el-input>
                    </el-form-item>
                    <el-form-item label="计划日期" class="selectMB10">
                        <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.createTimeBegin"  placeholder="选择起始日期" @change="selectedCreateTimeBegin"></el-date-picker>
                        &nbsp;至&nbsp;
                        <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.createTimeEnd"  placeholder="选择结束日期" @change="selectedCreateTimeEnd"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划来源" class="selectMB10">
                        <el-select v-model="formInline.source" placeholder="请选择" size="mini" clearable>
                            <el-option v-for="(planSources,index) in planSourcesLists" :key="index" :label="planSources.label" :value="planSources.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="计划状态" class="selectMB10">
                        <el-select v-model="formInline.status" placeholder="请选择" size="mini" clearable>
                            <el-option v-for="(planStatus,index) in planStatusLists" :key="index" :label="planStatus.label" :value="planStatus.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item class="selectMB10">
                        <el-checkbox v-model="checked">未完全分配的计划</el-checkbox>
                    </el-form-item>
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryByPlan(pageIndex,pageSize)">查询</el-button>
                    </el-form-item>
                </el-form>  
                <!--表格-->
                <label class="default-label">计划列表：</label>
                <!-- 
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="checkAll">全选</el-button>
                -->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="reverseSelection(tableData)">反选</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="planSummary" v-if="powerFlag">计划汇总</el-button>
                
                <el-table ref="multipleTable" :data="tableData" border style="width: 100%;" v-loading.body="loading1" element-loading-text="拼命加载中" @selection-change="handleSelectionChange">
                    <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                    <!--   :reserve-selection="true"
                   <el-table-column label="选择" header-align="center" align="center" width="40">
                       <template scope="scope">
                           <el-checkbox size="mini" @change="selectPlanLineItems(scope.$index, scope.row,$event)"  :label="scope.row.id"></el-checkbox>
                            aggregationStatus
                       </template>
                   </el-table-column>
                   -->
                    <el-table-column type="selection" align="center"  width="40"></el-table-column>

                    <el-table-column prop="planCode" label="计划编号" header-align="center" width="120"  show-overflow-tooltip>
                        <template scope="scope">
                            <el-button size="mini" @click="checkTheDetails(scope.$index, scope.row)" class="blueFont">{{scope.row.planCode}}</el-button>
                        </template>
                    </el-table-column>
                    <el-table-column prop="sourceWord" label="来源" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="totalCount" label="总件数" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="currencyCodeWord" label="币别" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="total" label="总金额" header-align="center" align="right"></el-table-column>
                    <el-table-column prop="statusWord" label="状态" header-align="center" width="80" align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="creatorName" label="制定人" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="createTime" label="制定日期" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="reviewerName" label="审核人" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="reviewTime" label="审核日期" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="approverName" label="审批人" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="approvalTime" label="审批日期" header-align="center" show-overflow-tooltip></el-table-column>
                </el-table>
                <!--分页-->
                <el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageIndex"  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>

            </el-tab-pane>
            <el-tab-pane label="按备件汇总" name="2">
                <el-form :inline="true" :model="formInline2" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
                    <el-form-item label="计划编号" class="selectMB10">
                        <el-input size="mini" v-model="formInline2.planCode" placeholder="请输入计划编号"></el-input>
                    </el-form-item>
                    <el-form-item label="计划日期" class="selectMB10">
                        <el-date-picker type="date" size="mini" :editable="false" v-model="formInline2.createTimeBegin" placeholder="选择开始日期"@change="selectedCreateTimeBegin"></el-date-picker>
                        &nbsp;至&nbsp;
                        <el-date-picker type="date" size="mini" :editable="false" v-model="formInline2.createTimeEnd"  placeholder="选择结束日期"@change="selectedCreateTimeEnd"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划来源" class="selectMB10">
                        <el-select v-model="formInline2.source" placeholder="请选择" size="mini" clearable>
                            <el-option v-for="(planSources,index) in planSourcesLists" :key="index" :label="planSources.label" :value="planSources.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="计划状态" class="selectMB10">
                        <el-select v-model="formInline2.status" placeholder="请选择" size="mini" clearable>
                            <el-option v-for="(planStatus,index) in planStatusLists" :key="index" :label="planStatus.label" :value="planStatus.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="备件编码" class="selectMB10">
                        <el-input size="mini" v-model="formInline2.materialCode" placeholder="请输入备件编码"></el-input>
                    </el-form-item>
                    <el-form-item label="备件名称" class="selectMB10">
                        <el-input size="mini" v-model="formInline2.materialName" placeholder="请输入备件名称"></el-input>
                    </el-form-item>
                    <el-form-item class="selectMB10">
                        <el-button class="bolder outsideBtnBS selectAll" :disabled="select2Disabled" size="mini" type="danger" @click="queryBySpare(pageIndex2,pageSize2)">查询</el-button>
                    </el-form-item>
                </el-form>  
                <!--表格-->
                <label class="default-label">备件列表：</label>
                <!-- 
                <el-button class="bolder outsideBtnBS" size="mini" type="danger"  @click="">全选</el-button>
                -->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="reverseSelection(tableData2)">反选</el-button>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="planSummary" v-if="powerFlag">计划汇总</el-button>
                <el-table :data="tableData2" border style="width: 100%;" v-loading.body="loading2" element-loading-text="拼命加载中" @selection-change="handleSelectionChange">
                    <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                    <!--
                    <el-table-column label="选择" header-align="center" align="center" width="40">
                        <template scope="scope">
                            <el-checkbox size="mini"  :label="scope.row.id" @change="selectPlanLineItems(scope.$index, scope.row,$event)"></el-checkbox>
                        </template>
                    </el-table-column>
                    -->
                    <el-table-column type="selection" align="center"  width="40"></el-table-column>
                    <el-table-column prop="planCode" label="计划编号" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="materialCode" label="备件编码" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="standard" label="规格" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="unit" label="计量单位" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="quantity" label="计划数量" header-align="center" width="80"></el-table-column>
                    <el-table-column prop="price" label="单价" header-align="center" width="80" align="right"></el-table-column>
                    <el-table-column prop="amount" label="计划总金额" header-align="center" width="80" align="right"></el-table-column>
                    <el-table-column prop="deliveryTimeExpectation" label="期望到货日期" header-align="center" show-overflow-tooltip></el-table-column>
                </el-table>
                <!--分页-->
                <el-pagination v-if="isPaging" @size-change="handleSizeChange2" @current-change="handleCurrentChange2"
                               :current-page="pageIndex2"  :page-size="pageSize2"
                               layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage2"
                               :total="totalNumber2"></el-pagination>
            </el-tab-pane>
            <!-- 点击每行的备件编码查看明细 明细弹窗 -->
            <el-dialog id="replaceMask" title="明细" :visible.sync="checkTheDetailsVisible" size="large" :lock-scroll="false">
                <el-table :data="detailsData" border style="width: 100%">
                    <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                    <!-- -->
                    <el-table-column property="detailsDataSource" label="计划来源" header-align="center" width="80" show-overflow-tooltip></el-table-column>
                    
                    <el-table-column property="materialSubclass" label="计划分类" header-align="center" width="80" show-overflow-tooltip> </el-table-column>
                    <el-table-column property="materialCode" label="备件编号" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column property="materialName" label="备件名称" header-align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column property="standard" label="规格" header-align="center" width="80" show-overflow-tooltip> </el-table-column>
                    <el-table-column property="unit" label="计量单位" header-align="center" width="80" show-overflow-tooltip> </el-table-column>
                    <el-table-column property="quantity" label="计划数量" header-align="center" width="80"></el-table-column>
                    <el-table-column property="price" label="单价" header-align="center" align="right" width="80"> </el-table-column>
                    <el-table-column property="amount" label="计划总金额" header-align="center" align="right" width="100"> </el-table-column>
                    <el-table-column property="deliveryTimeExpectation" label="期望到货日期" header-align="center" width="100" show-overflow-tooltip></el-table-column>
                    <el-table-column property="remark" label="备注" header-align="center" show-overflow-tooltip></el-table-column>
                </el-table>
            </el-dialog>
        </el-tabs>

        <!-- 计划中存在无效报价的备件 -->
        <el-dialog id="noValidQuotation" title="备件有效价格提示信息" :visible.sync="noValidQuotationVisible" size="small" :lock-scroll="false">
            <p style="line-height:32px;color:#e02222;">系统中，以下备件默认供应商的有效报价不存在，请先完善备件价格！</p>
            <el-form :inline="true" :model="noValidQuotationForm" ref="noValidQuotationForm" class="demo-form-inline">
                <el-form-item label="询价开始日期" prop="enquiryStartDate" :rules="[{ required: true, message: '询价开始日期不能为空'}]" class="selectMB10">
                    <el-date-picker type="date" size="mini" :editable="false" v-model="noValidQuotationForm.enquiryStartDate" @change="selectedEnquiryStartDate"></el-date-picker>
                </el-form-item>
                <el-form-item label="询价结束日期" prop="enquiryEndDate" :rules="[{ required: true, message: '询价结束日期不能为空'}]" class="selectMB10">
                    <el-date-picker type="date" size="mini" :editable="false" v-model="noValidQuotationForm.enquiryEndDate" @change="selectedEnquiryEndDate"></el-date-picker>
                </el-form-item>
                <el-form-item label="" class="selectMB10">
                    <el-button size="mini" type="danger" class="bolder outsideBtnBS" style="margin-left:0!important;" @click="createQuotationDetails">创建报价明细</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="gridData" border style="width: 100%">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                <el-table-column property="code" label="备件编码" header-align="center" align="center" width="100" show-overflow-tooltip> </el-table-column>
                <el-table-column property="name" label="备件名称" header-align="center" width="200" show-overflow-tooltip></el-table-column>
                <el-table-column property="standard" label="规格" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="unit" label="计量单位" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column property="quantity" label="数量" header-align="center"></el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <!--分页 
                <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange"  :current-page.sync="currentPage3" :current-page="pageIndex" :page-sizes="[1, 2, 3 , 4, 5]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>-->
            </span>
        </el-dialog>
    </div>
   
</template>
<script>
  export default  {
    data() {
      return {
        activeName: '1',
        loading1:false,
        loading2:false,
        legalPersonDropDown:[],   //法人名称下拉列表中的值
        planStatusLists:[],   //计划状态下拉列表中的值
        planSourcesLists:[],   //计划来源下拉列表中的值
        // 按计划汇总
        formInline:{
            legalPersonId:"",
            legalPersonName:"",
            planCode:"",
            createTimeBegin:"",
            createTimeEnd:"",
            source:"",
            status:""
        },
        checked:false,
        noValidQuotationVisible:false,     // 按计划汇总   计划中存在无效报价的备件的弹窗显示与否
        noValidQuotationForm:{
            enquiryStartDate:"",
            enquiryEndDate:""
        }, // 按计划汇总   计划中存在无效报价的备件的表单
        gridData:[], // 按计划汇总   计划中存在无效报价的备件的表格
        invalidQuotationlegalPersonId:"",    //计划中存在无效报价的备件的法人ID
        currencyCode:"",//计划中存在无效报价的备件的币别
        tableData:[],    //按计划查询 的数据
        isPaging:false,
        pageIndex:1,
        pageSize:10,
        totalPage:2,
        totalNumber:18,

        // 按备件汇总
        formInline2:{
            planCode:"",
            createTimeBegin:"",
            createTimeEnd:"",
            source:"",
            status:"",
            materialCode:"",
            materialSubclass:""
        },
        checked2:"false",
        tableData2:[],     // 按备件查询 的数据
        isPaging2:true,
        pageIndex2:1,
        pageSize2:10,
        totalPage2:2,
        totalNumber2:18,

        // noValidQuotationVisible2:false,     // 按备件汇总   计划中存在无效报价的备件的弹窗显示与否
        // noValidQuotationForm2:{
        //     enquiryStartDate:"",
        //     enquiryEndDate:""
        // }, // 按备件汇总   计划中存在无效报价的备件的表单
        // gridData2:[],   // 按备件汇总   计划中存在无效报价的备件的表格

        checkTheDetailsVisible:false,    // 点击每行的备件编码查看明细
        detailsData:[],
        // detailsDataSource:"",    //按计划汇总 点击计划编号 查看明细中的计划来源

        ids:[],      // 选中的每个计划行的id
        //权限
        powerFlag:false,
        //查询禁用
        selectDisabled:false,
        select2Disabled:false
      };
    },
    computed:{
          powerData(){
              return this.$store.state.powerData;
          }
      },
      watch:{
          powerData(){
              var _this=this;
              for(var i=0;i<_this.powerData.length;i++){
                  if(_this.powerData[i]=="ROLE_security_planSummary_operation"){
                      //计划汇总权限
                      _this.powerFlag=true;
                  }
              }
          }
      },
    mounted:function(){
        var _this=this;
        _this.$store.commit('currentActive', 'PlanSummary');
        // 按计划汇总   查询条件 法人名称 下拉列表的值
        _this.legalPersonDropDownValue();
        _this.planConditionDropDownValue();   // 查询条件  计划状态、计划来源 下拉列表的值
        // //ajax前后查询按钮禁用
        // $(".selectAll").ajaxStart(function(){
        //     _this.selectDisabled=true;
        // });
        // $(".selectAll").ajaxStop(function(){
        //     _this.selectDisabled=false;
        // });
        // 按计划汇总   查询
        _this.queryByPlan(_this.pageIndex,_this.pageSize);
        //判断权限
        for(var i=0;i<_this.powerData.length;i++){
            if(_this.powerData[i]=="ROLE_security_planSummary_operation"){
                //计划汇总权限
                _this.powerFlag=true;
            }
        }
    },
    methods: {
        // 按计划汇总  按备件汇总 tab
        handleClick(tab, event) {
            // console.log(tab, event);
            var _this=this;
            _this.formInline.source="";
            _this.formInline.status="";
            _this.formInline2.source="";
            _this.formInline2.status="";
            if(tab.name==1){
                _this.queryByPlan(_this.pageIndex,_this.pageSize); 
            }else if(tab.name==2){
                _this.queryBySpare(_this.pageIndex2,_this.pageSize2); 
            }
        },
        // 选择计划开始日期
        selectedCreateTimeBegin(val){
            var _this=this;
            _this.formInline.createTimeBegin = val;
        },
        // 选择计划结束日期
        selectedCreateTimeEnd(val){
            var _this=this;
            _this.formInline.createTimeEnd = val;
        },
        // 按计划汇总 查询条件 法人名称
        legalPersonDropDownValue(){  //法人名称下拉列表值
            var _this = this;
            $.ajax({
                type:'GET',
                url:_this.procurement_service+"legalPerson/ofCurrentUser",
                cache:false,
                success:function(data){
                    if(data.success){
                        _this.legalPersonDropDown = data.data;
                        if(_this.legalPersonDropDown.length == 1){
                            _this.formInline.legalPersonName = _this.legalPersonDropDown[0].legalPersonName;
                            _this.formInline.legalPersonId = _this.legalPersonDropDown[0].id;
                        }
                    }else{
                        _this.common.errorTip(data.errorMessage);
                    }
                }
            })
        },
        // 下拉列表选择法人名称
        selectLegalPersonName(){
            var _this=this;
            for(var i=0;i<_this.legalPersonDropDown.length;i++){
                if(_this.formInline.legalPersonName==_this.legalPersonDropDown[i].legalPersonName){
                    _this.formInline.legalPersonId=_this.legalPersonDropDown[i].id;
                }
            }
        },
        //  计划状态、计划来源 下拉列表
        planConditionDropDownValue(){
            var _this=this;
            var tmp = ["planStatus","source"];
            $.ajax({
                type:'POST',
                url:_this.procurement_service+'procurement/getPullDownList',
                cache:false,
                data:JSON.stringify(tmp),
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success:function(data){
                    if(data.success){
                        // console.log(data.data);
                        _this.planStatusLists = data.data.planStatus;    //计划状态
                        _this.planSourcesLists=data.data.source;    // 计划来源
                    }else{
                        _this.common.errorTip(data.errorMessage);
                    }
                }
            })
        },
        // 按计划汇总   查询
        queryByPlan(pageIndex,pageSize){
            var _this=this;
            _this.loading1=true;
            _this.loading2=false;
            var tmp={
                legalPersonId:_this.formInline.legalPersonId,
                planCode:_this.formInline.planCode,
                createTimeBegin:_this.formInline.createTimeBegin,
                createTimeEnd:_this.formInline.createTimeEnd,
                status:_this.formInline.status,
                aggregationStatus:_this.checked,
                pageIndex:pageIndex,
                pageSize :pageSize
                };
            // 如果计划来源有值，添加这个参数
            if(_this.formInline.source){      
                tmp.source=_this.formInline.source;
            }
            _this.selectDisabled=true;
            $.ajax({
                type: 'POST',
                url: _this.procurement_service+"planAggregation/queryPlan",
                cache: false,
                data:JSON.stringify(tmp),
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                    if (data.success) {
                        _this.loading1=false;
                         var arr=data.data.dataList;
                        for(var i=0;i<arr.length;i++){   //金额保留两位
                            arr[i].total=arr[i].total.toFixed(2);
                        }
                        _this.tableData=arr;
                        // _this.tableData=data.data.dataList; 

                        _this.isPaging=true;      //显示分页
                        _this.totalNumber=data.data.totalNumber;    //总条数
                        _this.totalPage=data.totalPage;    //总页数
                    }else{
                        _this.common.errorTip(data.errorMessage);
                    }
                    _this.selectDisabled=false; 
                }
            });
        },
        // 按计划汇总    分页
        handleSizeChange(val){
            // console.log(`每页 ${val} 条`);
            var _this=this;
            _this.pageSize=val;
            _this.queryByPlan(_this.pageIndex, _this.pageSize);
        },
        // 按计划汇总    点击页码分页查询点击事件
        handleCurrentChange(val){
            // console.log(`当前页: ${val}`);
            var _this=this;
            _this.pageIndex=val;
            _this.queryByPlan(_this.pageIndex, _this.pageSize);
        },
        // 按计划汇总 全选
        checkAll(){
            // var _this=this; 
            // for(var i=0;i<_this.tableData.length;i++){
            //     _this.tableData[i].aggregationStatus=true;
            // }
        }, 
        // selection-change	当选择项发生变化时会触发该事件 
        handleSelectionChange(val){
            // console.log(val);
            var _this=this;
            _this.ids=[];
            if(_this.activeName=="1"){
                for(var i=0;i<val.length;i++){
                    _this.ids.push(val[i].planId);
                }
            }else{
                for(var i=0;i<val.length;i++){
                    _this.ids.push(val[i].planItemId);
                }
            }
        },
        // 按计划汇总   反选
        reverseSelection(rows){
            // console.log(rows);
            var _this=this; 
            if (rows) {
                rows.forEach(row => {
                    _this.$refs.multipleTable.toggleRowSelection(row);
                });
            } else {
                _this.$refs.multipleTable.clearSelection();
            }
        },
        // // 按计划汇总 选择每一个行项目
        // selectPlanLineItems(index,row,event){
        //     var _this=this;
        //     if($(event.target).parent().attr("class").indexOf("is-checked")!=-1){
        //         _this.ids.push(row.planCode);   //选中的每个计划行的ID
        //     }else{
        //         _this.ids.pop(row.planCode);
        //     }
        // },
        // 按计划汇总 计划汇总按钮     按备件汇总  计划汇总按钮
        planSummary(){
            var _this=this;
            var dataFlag=true;
            if(_this.activeName == 1 && _this.tableData.length > 0){
                dataFlag=true;
            }else if(_this.activeName == 2 && _this.tableData2.length>0){
                dataFlag=true;
            }else{
                dataFlag=false;
            }
            if(dataFlag){
                if(_this.ids.length > 0){
                    var tmp={type:_this.activeName,ids:_this.ids};    //activeName 1按计划汇总   2按备件汇总
                    _this.invalidQuotationlegalPersonId="";
                    $.ajax({
                        type: 'POST',
                        url: _this.procurement_service+"planAggregation/save",
                        cache: false,
                        data:JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType: "application/json;charset=utf-8",     //*****
                        success: function (data) {
                            if (data.success) {
                                _this.$router.push({path:"/SummaryDetails",query:{planAggregationId:data.data.id}});
                            }else if(data.errorCode == "procurement.planAggregation.plan.active.price.not.exist"){
                                // 计划中备件存在无效报价
                                _this.noValidQuotationVisible=true;
                                _this.noValidQuotationForm.enquiryStartDate = "";
                                _this.noValidQuotationForm.enquiryEndDate = "";
                                _this.currencyCode=data.hint.currencyCode;
                                _this.gridData=data.hint.materialNoActivePrice;
                                _this.invalidQuotationlegalPersonId=data.hint.legalPersonId;
                            }else if(data.errorCode == "procurement.planAggregation.plan.default.provoder.not.exist"){
                                // 计划中备件没有默认供应商
                                var codeList=[];
                                for(var i=0;i<data.hint.length;i++){
                                    codeList.push(data.hint[i].code);
                                }
                                _this.common.errorTip(data.errorMessage +"["+ codeList +"]");
                            }else{
                                _this.common.errorTip(data.errorMessage);
                            }                           
                                
                        }
                    });
                }else{
                    _this.common.errorTip("没有选中数据！");
                }
            }else{
                _this.common.errorTip("列表中暂无数据！");
            }
            
        },

        // 按计划汇总  点击每行的备件编码查看明细
        checkTheDetails(index,row){
            var _this=this;
            _this.checkTheDetailsVisible=true;
            $.ajax({
                type: 'GET',
                url: _this.procurement_service+"plan/viewPlan?planId="+row.planId,
                cache: false,
                success: function (data) {
                    if (data.success) {
                        var arr=data.data.planItems;
                        //单价保留八位小数，总金额保留两位
                        for(var i=0;i<arr.length;i++){
                            arr[i].price=arr[i].price.toFixed(8);
                            arr[i].amount=arr[i].amount.toFixed(2);
                        }
                        _this.detailsData=arr;
                        for(var i=0;i<_this.detailsData.length;i++){
                            _this.detailsData[i].detailsDataSource=row.sourceWord;
                        }
                    }else
                        // console.log(data.errorMessage);                             
                        _this.common.errorTip(data.errorMessage);
                }
            });

        },

        // 按备件汇总   查询
        queryBySpare(pageIndex,pageSize){
            var _this=this;
            _this.loading2=true;
            _this.loading1=false;
            var tmp={planCode:_this.formInline2.planCode,createTimeBegin:_this.formInline2.createTimeBegin,createTimeEnd:_this.formInline2.createTimeEnd,status:_this.formInline2.status,materialCode:_this.formInline2.materialCode,materialName:_this.formInline2.materialName,
            pageIndex:pageIndex,pageSize :pageSize};
            // 如果计划来源有值，添加这个参数 source:_this.formInline2.source,
            if(_this.formInline2.source){      
                tmp.source=_this.formInline2.source;
            }
            _this.select2Disabled=true;
            $.ajax({
                type: 'POST',
                url: _this.procurement_service+"planAggregation/queryMaterial",
                cache: false,
                data:JSON.stringify(tmp),
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                    if (data.success) {
                        _this.loading2=false;
                        // console.log(data.data);
                        //单价保留八位小数，总金额保留两位
                        var arr=data.data.content;
                        for(var i=0;i<arr.length;i++){
                            arr[i].price=arr[i].price.toFixed(8);
                            arr[i].amount=arr[i].amount.toFixed(2);

                        }
                        _this.tableData2=arr;
                        _this.isPaging=true;      //显示分页
                        _this.totalNumber2=data.data.totalElements;    //总条数
                        _this.totalPage2=data.totalPages;    //总页数
                    }else{
                        _this.common.errorTip(data.errorMessage);
                    }                         
                    _this.select2Disabled=false;   
                }
            });


        },
        // 按计划汇总    分页
        handleSizeChange2(val){
            // console.log(`每页 ${val} 条`);
            var _this=this;
            _this.pageSize2=val;
            _this.queryBySpare(_this.pageIndex2, _this.pageSize2);
        },
        // 按计划汇总    点击页码分页查询点击事件
        handleCurrentChange2(val){
            // console.log(`当前页: ${val}`);
            var _this=this;
            _this.pageIndex2=val;
            _this.queryBySpare(_this.pageIndex2, _this.pageSize2);
        },
        // 存在无效报价的备件 备件提示信息 询价开始日期
        selectedEnquiryStartDate(val){
            var _this=this;
            _this.noValidQuotationForm.enquiryStartDate = val;
            if(_this.noValidQuotationForm.enquiryEndDate && val > _this.noValidQuotationForm.enquiryEndDate){
                _this.common.errorTip("询价开始日期不能大于询价结束日期");
                _this.noValidQuotationForm.enquiryStartDate = "";
            };
        },
        // 存在无效报价的备件 备件提示信息 询价结束日期
        selectedEnquiryEndDate(val){
            var _this=this;
            _this.noValidQuotationForm.enquiryEndDate = val;
            if(_this.noValidQuotationForm.enquiryStartDate && val < _this.noValidQuotationForm.enquiryStartDate){
                _this.common.errorTip("询价结束日期不能小于询价开始日期");
                _this.noValidQuotationForm.enquiryEndDate = "";
            };
        },
        // 创建报价明细
        createQuotationDetails(){
            var _this=this;
            var enquiryStartDate,enquiryEndDate,materials;
            _this.$refs["noValidQuotationForm"].validate((valid) => {
                if (valid) {
                    enquiryStartDate = _this.noValidQuotationForm.enquiryStartDate,
                    enquiryEndDate = _this.noValidQuotationForm.enquiryEndDate;
                    materials=_this.gridData;
                    var tmp={legalPersonId:_this.invalidQuotationlegalPersonId,enquiryStartDate:enquiryStartDate,enquiryEndDate:enquiryEndDate,currencyCode:_this.currencyCode,materialNoActivePrice:materials};
                    $.ajax({
                        type: 'POST',
                        url: _this.procurement_service+"quotationList/add",
                        cache: false,
                        data:JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType: "application/json;charset=utf-8",     //*****
                        success: function (data) {
                            if (data.success) {
                                _this.common.successTip("数据已发送！");
                                //_this.$router.push("/PlanSummary");
                            }else
                                _this.common.errorTip(data.errorMessage); 
                        }
                    });
                } else {
                    // console.log('error submit!!');
                    _this.common.errorTip("存在未填写的必填项！");
                    return false;
                }
            });
        },
        // // ===================================
        // successTip(p) {     //成功时的提示信息
        //     this.$notify({
        //         title: '成功',
        //         message: p,
        //         type: 'success'
        //     });
        // },
        // errorTip(p) {     //错误提示
        //     this.$notify.error({
        //         title: '错误',
        //         message: p
        //     });
        // }   



        
    }
  };
</script>